// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-11

package responses

import (
	"server/app/http/models"
	"server/app/kind"
)

// GoodsResponse
// 订单信息.
type GoodsResponse struct {
	Id         kind.GoodsId
	ArcadeId   kind.ArcadeId
	CategoryId kind.GoodsCategory
	PurchaseId int64
	Unit       kind.GoodsUnit
	UnitText   string

	State        kind.GoodsState
	StateFlag    string
	StateText    string
	StateForSale bool

	Stock       kind.GoodsStock
	SalePrice   kind.Balance
	SaleCount   kind.GoodsStock
	SaleTotal   kind.GoodsStock
	LockedCount kind.GoodsStock

	Name       string
	Image      string
	CreateTime string
}

// With
// 数据绑定.
func (o *GoodsResponse) With(m *models.Goods) *GoodsResponse {
	o.Id = m.Id
	o.ArcadeId = m.ArcadeId
	o.CategoryId = m.CategoryId
	o.PurchaseId = m.PurchaseId
	o.Unit = m.Unit
	o.UnitText = o.Unit.Text()
	o.State = m.State
	o.StateFlag = m.State.Flag()
	o.StateText = m.State.Text()
	o.StateForSale = m.State.IsForSale()
	o.Stock = m.Stock
	o.SalePrice = m.SalePrice
	o.SaleCount = m.SaleCount
	o.SaleTotal = m.SaleTotal
	o.LockedCount = m.LockedCount
	o.Name = m.Name
	o.Image = m.Image
	o.CreateTime = m.CreatedAt.Time().Format("2006/01/02")
	return o
}
